package com.yanqu.road.server.cross3server.cmd.server;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.server.CrossChannelRouteProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Cross3Protocol.C3_ROUTE_CHANNEL_MSG, desc = "转发消息到跨地区")
public class RouteChannelMsgCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossChannelRouteProto.RouteChannelMsg reqMsg = CrossChannelRouteProto.RouteChannelMsg.parseFrom(packet.getBytes());

        // 拿一下真实的协议号
        int channelCode = reqMsg.getChannelCode();
        byte[] msg = reqMsg.getMsg().toByteArray();
        if(packet.getPlayerId() != -1){
            YanQuMessage message = YanQuMessageUtils.buildMessageByte(channelCode,packet.getPlayerId(),msg);
            MessageHelper.sendChannelServer(message);
        }else{
            // 用真实的协议号转发到跨地区
            YanQuMessage message = YanQuMessageUtils.buildMessageByte(channelCode, msg);
            MessageHelper.sendChannelServer(message);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
